package com.timeriver.domain.dto;

import com.timeriver.domain.enums.ModelCategory;
import com.timeriver.domain.enums.StatusCategory;
import com.timeriver.utils.UUIDUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

@Data
public class SparkModelDto {

    private String id;

    private String name;

    private String description;

    private Integer category;

    private Integer status;

    private Integer newVersionNum;

    private Integer currentVersion;

    private String modelPath;

    private String dataFormat;

    private String secretKey;

    private Integer disabled;

    private String topicName;

    private Date createTime;

    private Date updateTime;

    private String categoryName;

    private String statusName;

    public String getTopicName() {
        return category != 0 ? UUIDUtil.getTimestampUUID("topic", "-") : null;
    }

    public Integer getNewVersionNum() {
        return this.newVersionNum == null ? 1 : this.newVersionNum;
    }

    public Date getCreateTime() {
        return null == createTime ? new Date() : this.createTime;
    }

    public Integer getDisabled() {
        return null == this.disabled ? 0 : this.disabled;
    }

    public Integer getCategory() {
        return category == null ? ModelCategory.getCategory(categoryName) : this.category;
    }

    public String getSecretKey() {
        return StringUtils.isEmpty(secretKey) ? UUIDUtil.getRandomUUID() : secretKey;
    }

    public Integer getStatus() {
        return status == null ? (statusName == null ? 0 : StatusCategory.getStatus(statusName)) : this.status;
    }

    public String getDataFormat() {
        if (StringUtils.isEmpty(dataFormat)) {
            return null;
        }
        /** 去除请求数据格式中的空格回车等符号 */
        return dataFormat.replaceAll("\\s*|\t|\r|\n", "");
    }
}
